﻿module fitbit {
    'use strict';

    export interface IFitbiLastYearFatInfo {
        tempData: string;
    }

    export interface IFitbiActivityInfo {
    }

    export interface IFitbitService {
        getLastYearFat(): ng.IPromise<IFitbiLastYearFatInfo>;
        getActivity(): ng.IPromise<IFitbiActivityInfo>;
    }

    class FitbitService implements IFitbitService {

        static $inject = ['$http','$q'];
        constructor(private $http: ng.IHttpService, private $q: ng.IQService) {

        }

        getLastYearFat(): ng.IPromise<IFitbiLastYearFatInfo> {
            return this.$http.get('/Fitbit/LastYearFat')
                .then((response: ng.IHttpPromiseCallbackArg<IFitbiLastYearFatInfo>): IFitbiLastYearFatInfo => {
                    return response.data;
                });
        }

        getActivity(): ng.IPromise<IFitbiLastYearFatInfo> {
            var data = [
                {
                    'val_0': 0.993,
                    'val_1': 3.894,
                    'val_2': 8.47,
                    'val_3': 14.347,
                    'x': new Date(2015, 4, 3)
                },
                {
                    'val_0': 1.947,
                    'val_1': 7.174,
                    'val_2': 13.981,
                    'val_3': 19.991,
                    'x': new Date(2015, 4, 4)
                },
                {
                    'val_0': 2.823,
                    'val_1': 9.32,
                    'val_2': 14.607,
                    'val_3': 13.509,
                    'x': new Date(2015, 4, 5)
                },
                {
                    'val_0': 3.587,
                    'val_1': 9.996,
                    'val_2': 10.132,
                    'val_3': -1.167,
                    'x': new Date(2015, 4, 6)
                },
                {
                    'val_0': 4.207,
                    'val_1': 9.093,
                    'val_2': 2.117,
                    'val_3': -15.136,
                    'x': new Date(2015, 4, 7)
                },
                {
                    'val_0': 0.993,
                    'val_1': 3.894,
                    'val_2': 8.47,
                    'val_3': 14.347,
                    'x': new Date(2015, 4, 8)
                },
                {
                    'val_0': 3.587,
                    'val_1': 9.996,
                    'val_2': 10.132,
                    'val_3': -1.167,
                    'x': new Date(2015, 4, 9)
                },
            ];

            var defer = this.$q.defer();
            defer.resolve(data);

            return defer.promise;
        }
    }

    angular.module('fitbitApp').service('FitbitService', FitbitService);
}